home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / COMPARE.CPP < prev    next >
C/C++ Source or Header  |  1994-12-13  |  5KB  |  190 lines

  1. // COMPBBS.CPP                                 1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9. #include <time.h>
  10.  
  11. #define PROGRAM "COMPARE"   // Name of module
  12. /*********************************************************************/
  13.  
  14. typedef struct
  15. {
  16.     int area;
  17.     char filename1[FLENGTH];
  18.     char filename2[FLENGTH];
  19. } COMPARE_INFO;
  20.  
  21. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  22. static void print_match(AU *au, char *string)
  23. {
  24.     COMPARE_INFO *in = (COMPARE_INFO *)au->info;
  25.  
  26.     if (in->area != 0)
  27.         au_printf(au, "@?1%s@?H (%d)\n", string, in->area);
  28.     else
  29.         au_printf(au, "@?1%s@?H\n", string);
  30. }
  31. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  32. static int look_for_files(AU *au, LISTPTR *listptr, HANDLE *handle)
  33. {
  34.     char string[FILE_SIZE];
  35.     LIST *el;
  36.     int found;
  37.     COMPARE_INFO *in = (COMPARE_INFO *)au->info;
  38.  
  39.     handle->seek(0L, SEEK_SET);
  40.  
  41.     while (get_next_file_name(au, handle, string, &in->area) != EOF)
  42.     {
  43.         found = FALSE;
  44.         for (el = listptr->head; el != NULL; el=el->next)
  45.         {
  46.             if (strcmp(el->data, string) == 0)
  47.             {
  48.                 found = TRUE;
  49.                 break;
  50.             }
  51.         }
  52.         if (!found)
  53.             print_match(au, string);
  54.     }
  55.     return 0;
  56. }
  57.  
  58. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  59. static int compare(AU *au, char *filename1, char *filename2)
  60. {
  61.     HANDLE handle1, handle2;
  62.     int ret_code = 0;
  63.     char string[FILE_SIZE];
  64.     LISTPTR listptr;
  65.     COMPARE_INFO *in = (COMPARE_INFO *)au->info;
  66.  
  67.     if (handle1.open(au, filename1, O_RDONLY) != SUCCESS)
  68.     {
  69.         au_printf_error(au, "Unable to open %s", filename1);
  70.         return -1;
  71.     }
  72.     if (handle2.open(au, filename2, O_RDONLY) != SUCCESS)
  73.     {
  74.         au_printf_error(au, "Unable to open %s", filename2);
  75.         ret_code = -1;
  76.         goto Error0;
  77.     }
  78.  
  79.     /* See what 2 has that 1 does not */
  80.     while (get_next_file_name(au, &handle1, string, &in->area) != EOF)
  81.     {
  82.         if (wildcard_compare(au, string, au->partial))
  83.             listptr.add(string);
  84.     }
  85.     au_printf(au, "@?7Files in %s not in %s --------------:@?H\n", filename2, filename1);
  86.     look_for_files(au, &listptr, &handle2);
  87.     listptr.destroy();
  88.  
  89.     handle2.seek(0L, SEEK_SET);
  90.  
  91.     /* See what 1 has that 2 does not */
  92.     while (get_next_file_name(au, &handle2, string, &in->area) != EOF)
  93.     {
  94.         if (wildcard_compare(au, string, au->partial))
  95.             listptr.add(string);
  96.     }
  97.     au_printf(au, "@?7Files in %s not in %s --------------:@?H\n", filename1, filename2);
  98.     look_for_files(au, &listptr, &handle1);
  99.     listptr.destroy();
  100.  
  101. Error1:
  102.     handle2.close();
  103. Error0:
  104.     handle1.close();
  105.     return ret_code;
  106. }
  107. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  108. static int disp_list(AU *au, char *filename)
  109. {
  110.     HANDLE handle;
  111.     char string[FILE_SIZE];
  112.     COMPARE_INFO *in = (COMPARE_INFO *)au->info;
  113.  
  114.     if (handle.open(au, filename, O_RDONLY) != SUCCESS)
  115.     {
  116.         au_printf_error(au, "Unable to open %s", filename);
  117.         return -1;
  118.     }
  119.  
  120.     /* Get list */
  121.     while (get_next_file_name(au, &handle, string, &in->area) != EOF)
  122.     {
  123.         if (wildcard_compare(au, string, au->partial))
  124.             print_match(au, string);
  125.     }
  126.     handle.close();
  127.     return 0;
  128. }
  129. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  130. static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
  131.                             PARSE_TYPE type)
  132. {
  133.     COMPARE_INFO *in = (COMPARE_INFO *)au->info;
  134.  
  135.     switch (type)
  136.     {
  137.     case PARSE_PARAM_OPTION:
  138.         switch (option)
  139.         {
  140.         case '?':
  141.             au_syntax_message(au, "COMpare");
  142.             au_printf(au,
  143.                 "file1 [file2] [@?1filespec@?H]\n\n");
  144.             exit(0);
  145.         default:
  146.             au_invalid_option(au, PROGRAM, option);
  147.         }
  148.         return TRUE;
  149.     case PARSE_FILESPEC:
  150.         if (strchr(cur_argv, '?') || strchr(cur_argv, '*'))
  151.             strcpy(au->partial, cur_argv);
  152.         else if (in->filename1[0] == '\0')
  153.             strcpy(in->filename1, cur_argv);
  154.         else if (in->filename2[0] == '\0')
  155.             strcpy(in->filename2, cur_argv);
  156.         else
  157.             strcpy(au->partial, cur_argv);
  158.         return TRUE;
  159.     case PARSE_POST_CHECK:
  160.         if (in->filename1[0] == '\0')
  161.         {
  162.             au_printf_error(au, "Need at least 1 file parameter");
  163.             exit(1);
  164.         }
  165.         if (au->partial[0] == '\0')
  166.             strcpy(au->partial, "*.*");
  167.         return TRUE;
  168.     }
  169.     return FALSE;
  170. }
  171. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  172. int main_compare(AU *au, int argc, char *argv[])
  173. {
  174.     COMPARE_INFO *in;
  175.  
  176.     in = (COMPARE_INFO *)au_malloc(au, sizeof(COMPARE_INFO));
  177.     memset(in, '\0', sizeof(COMPARE_INFO));
  178.     au->info = in;
  179.     in->area = 0;
  180.  
  181.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  182.  
  183.     if (in->filename2[0] != '\0')
  184.         compare(au, in->filename1, in->filename2);
  185.     else
  186.         disp_list(au, in->filename1);
  187.     return 0;
  188. }
  189.  
  190.